package com.jt.www.common.controller;

import com.jt.www.common.service.RiskStartTimeService;
import com.jt.www.model.policyattribute.vo.RiskStartTimeVo;
import com.jt.www.model.reps.GenericDataResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by shaoyn on 2020/02/28.
 */
@Api(value = "产品开始时间配置", tags = {"RISK-STARTTIME-API"}, description = "产品开始时间配置")
@RestController
@RequestMapping(value = "/risk/time")
public class RiskStartTimeController {
    public static final Logger log = LoggerFactory.getLogger(RiskStartTimeController.class);

    @Autowired
    RiskStartTimeService riskStartTimeService;

    /**
     * 查询产品属性
     *
     * @param productCode 产品编号
     * @return
     */
    @ApiOperation(value = "通过产品编码得到当前投保的时间范围", notes = "通过产品编码得到当前投保的时间范围", httpMethod = "GET")
    @GetMapping(value = "/getStartTime")
    public ResponseEntity getStartTime(@ApiParam(value = "产品编号", required = true)
                                       @RequestParam(value = "productCode") String productCode) {

        try {
            RiskStartTimeVo riskStartTime = riskStartTimeService.getRiskStartTime(productCode);
            return GenericDataResponse.okWithData(riskStartTime);
        } catch (Exception e) {
            e.printStackTrace();
            return GenericDataResponse.errorWithMsg("查询失败");
        }
    }

}
